<template>
<view>
	<view class="header">
		<view class="city" @click="jump('/pages/city/index')">
			<view>{{city}}</view>
			<image src="/static/icon/address.png" />
		</view>
		<view @click="Login('/pages/company/index')" class="search">
			<icon size="14" type="search"></icon>
			<view>请输入相关职位或企业名称</view>
		</view>
	</view>
	<view class="uni-margin-wrap">
		<swiper class="swiper" circular indicator-dots="true" autoplay="true" interval="2000" duration="500">
			<swiper-item v-for='(item,index) in banner' :key="index">
				<image v-if="item.url" @click="jump(item.url)" class="swiper_img" :src="imgUrl+item.img"></image>
				<image v-else class="swiper_img" :src="imgUrl+item.img"></image>
			</swiper-item>
		</swiper>
	</view>
	
	<view class="emptyview"></view>
	<view class="addjob">
		<view @click="Login('/pages/job/index')">
			<text class="fa fa-user-o  fa-lg"></text>人才
		</view>
		<view @click="Login('/pages/company/index')">
			<text class="fa fa-building-o  fa-lg"></text>机构</view>
		<view @click="jumpOA()">
			<text class="fa fa-product-hunt  fa-lg"></text>店务</view>
	</view>
	
	<view class="navlist">
		  <view class="item" @click="Login('/pages/job/index?star=1')">
			  <image class="shares" src="/static/icon/star_user.png" />
			  <view class="titletxt">明星人才</view>
		  </view>
		  <view class="item" @click="jump('/pages/factory/index')">
			  <image class="shares" src="/static/icon/company_service.png" />
			  <view class="titletxt">企业服务</view>
		  </view>
		  
		  <view class="item" @click="Login('/pages/pointsMall/index')">
			  <image class="shares" src="/static/icon/score.png" />
			  <view class="titletxt">积分商城</view>
		  </view>
		  <view class="item" @click="jump('/pages/course/index')">
			  <image class="shares" src="/static/icon/score1.png" />
			  <view class="titletxt">培训专区</view>
		  </view>
	</view>
	<!--关注公众号-->
	<view class="subscribe" v-if="subscribe">
		<view class="message">关注公众号,可进行提现,获取服务通知</view>
		<button class="contact" @click="jump('/pages/user/wxRcode/index')">关注</button>
	</view>
	<!--注册赚红包-->
	<view class="uni-margin-wrap">
		<swiper class="swiper" circular :indicator-dots="false" :autoplay="true" :interval="2000" :duration="500">
			<swiper-item v-for='(item,index) in gg' :key="index">
				<image v-if="item.url" @click="jumpLogin(item.url)" class="swiper_img" :src="imgUrl+item.img"></image>
				<image v-else class="swiper_img" :src="imgUrl+item.img"></image>
			</swiper-item>
		</swiper>
	</view>
	<!--转租专区-->
	<view class="lease" v-if="lease.length > 0" @click="jump('/pages/lease/index')">
		<view class="leasetitle">
			<view></view>
			<view>转租专区</view>
		</view>
		<view class="more">更多...</view>
	</view>
	
	<view class="swiper-container1" v-if="lease.length > 0">
		<swiper indicator-color="rgba(0, 0, 0, .3)" indicator-active-color="#000000" autoplay="true" interval="3000">
			<swiper-item v-for='(item,index) in lease' :key="index" class="lease_content">
				<image class="lease_img" @click="jump('/pages/lease/info?id='+item.id)" :src="imgUrl+item.imgs[0]"></image>
				<view class="lease_title">
					<text>机构名称:{{item.name}}</text>
					<text class="lease_title_remark">联系人:{{item.name}}</text>
					<text class="lease_title_remark">客服电话:18322223377</text>
				</view>
			</swiper-item>
		</swiper>
	</view>
	<!--优质岗位推荐-->
	<view class="newstitle">
		<view></view>
		<view>优质岗位推荐</view>
	</view>
	<view class="type-ad-container">
		<view @click="Login('/pages/company/info?id='+item.id)" class="type-ad-navbar-item" v-for="(item,index) in company" :key="index">
			<image v-if="item.imgs.length > 0" :src="imgUrl+item.imgs[0]"></image>
			<image v-else :src="pubImg"></image>
			<view class="job">{{item.job}}</view>
			<view class="jobCity">工作地点:{{item.city}}</view>
			<view class="companyName">{{item.name}}</view>
		</view>
	</view>
	
</view>		
</template>

<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			pubImg:'/static/img1/noup1.jpg',
			banner:[],
			imgUrl:this.url,
			company:[],
			page:1,
			pageShow:true,
			gg:[],
			lease:[],
			subscribe:false,
			role:0,
			city:'全部'
		}
	},
	onShow:function(e){
		//console.log(uni.getStorageSync('system'));
		// uni.setStorageSync('uid',12)
		// uni.setStorageSync('role',3)
		this.company = [],
		this.pageShow = true,
		this.page = 1,
		uni.showLoading({  
		    title: '加载中'  
		});
		this.getBanner()
		this.getCompany()
		this.getGg()
		this.getLease()
		if(uni.getStorageSync('uid')){
		  this.getWx()
		}
	},
	methods: {
		getBanner:function(){
			var that = this;
			request({
				url: 'banner',
				method: 'get',
				success: (res) => {
					that.banner = res.data.data
				}
			})
		},
		getLease:function(){
		    var that = this;
		    request({
		    	url: 'company/is_lease',
		    	method: 'get',
		    	success: (res) => {
		    		that.lease = res.data.data.data
		    	}
		    })
		 },
		getGg:function(){
			var that = this;
			var data = {'type':6}
			request({
				url: 'banner',
				method: 'get',
				data:data,
				success: (res) => {
					that.gg = res.data.data
				}
			})
		},
		getCompany:function(){
			var that = this;
			if(this.city == '全部'){
				var city = '';
			}else{
				var city = this.city;
			}
			var data = {
				page:this.page,
				city:city
			}
			request({
				url:'company/hot',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.code == 1){
						if(res.data.data.last_page <= that.page){
							that.pageShow = false
						}
					    if(that.page == 1){
					        that.company = res.data.data.data
					    }else{
							var company = that.company
					        that.company = company.concat(res.data.data.data)
					    }
					}
				}
			})
		},
		Login:function(url){
			if(!uni.getStorageSync('uid')){
				//微信授权登陆
				uni.navigateTo({
					url:'/pages/index/guide'
				});
			}else{
				this.checkPhone(url)
			}
		},
		jump:function(url){
			uni.navigateTo({
				url:url
			});
		},
		onReachBottom:function(e){
			if(this.pageShow){
				this.page = this.page + 1
				uni.showLoading({
				    title: '加载中'  
				});
				this.getCompany()
			}
		},
		checkPhone:function(url){
			var that = this
			var data = {
			     'uid':uni.getStorageSync('uid')
			}
			request({
				url: 'member/phone',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.navigateTo({
						  url:url
						})
					 }else{
						uni.navigateTo({
						  url:'/pages/index/phone'
						})
					}
				}
			})
		},
		getWx:function(){
			var data = {'uid':uni.getStorageSync('uid')}
			var that = this
			request({
				url: 'user/wxUser',
				method: 'get',
				data:data,
				success: (res) => {
					
					if(res.data.code == 1){
						
					}else{
						that.subscribe = true
					}
				}
			})
		},
		jumpLogin:function(url){
			if(url == '/pages/login/index'){
				if(uni.getStorageSync('role') !== 1){
					uni.showToast({
						title: '您已注册成功,请勿重复注册!!',
						icon: "none", 
						position:'bottom',
					});
					return;
				}
			}
			uni.navigateTo({
			  url:url
			})
		},
		jumpStar:function(url){
			if(uni.getStorageSync('role') == 99){
				uni.navigateTo({
					url:url
				});
				return;
			}
			var data = {
				uid:uni.getStorageSync('uid')
			}
			var that = this
			request({
				url: 'vip/message',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.navigateTo({
							url:url
						})
					}else{
						uni.showToast({
							title: '白金VIP会员有此权限',
							icon: "none", 
							position:'bottom',
						});
					}
				},
			})
		},
		jumpOA:function(){
			var that = this
			if(!uni.getStorageSync('uid')){
				//微信授权登陆
				uni.navigateTo({
					url:'/pages/index/guide'
				});
				return;
			}
			var role = uni.getStorageSync('role')
			if(role == 1){
				//暂未确认身份
				uni.navigateTo({
				  url:'/pages/login/index'
				})
				return;
			}
			if(uni.getStorageSync('oaRole')){
				if(uni.getStorageSync('oaRole') == 1 || uni.getStorageSync('oaRole') == 3){
					this.insertLog()
				}
				uni.navigateTo({
				  url:'/manage/index'
				})
				return;
			}
			var data = {
				'role':uni.getStorageSync('role'),
				'uid':uni.getStorageSync('uid')
			}
			request({
				url: 'manage/role',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.setStorageSync('oaRole',res.data.data.oaRole)
						uni.setStorageSync('oa_id',res.data.data.oa_id)
						if(res.data.code == 1){
							if(res.data.data.oaRole == 1 || res.data.data.oaRole == 3){
								that.insertLog()
							}
							//已绑定
							uni.navigateTo({
							  url:'/manage/index'
							})
						}
					}
				},
			})
		},
		insertLog:function(){
			var data = {
				oa_id:uni.getStorageSync('oa_id'),
				company_uid:uni.getStorageSync('uid')
			}
			var that = this
			request({
				url: 'manage/log/add',
				method: 'post',
				data:data,
				success: (res) => {
					//console.log(res)
				},
			})
		}
	}
}
</script>
<style scoped>
	@import url("./css/index.css");
</style>